window.pkl = {
    version: 0.1
}

var config = require('./../libs/config')

var ___notIn___ = function(par) {
    var isArray = par instanceof Array;
    if (!isArray) {
        throw par + ' must be type of Array';
    }
    for (var i = 0; i < par.length; ++i) {
        if (this.valueOf() === par[i]) {
            return true;
        }
    }
    return false;
}
String.prototype.inArray = ___notIn___;
Number.prototype.inArray = ___notIn___;
Boolean.prototype.inArray = ___notIn___;

var noAuth = [
    '',
    '#/login',
    '#/regist',
    '#/verifyCode',
    '#/resetpwd'
]


window.location.hash.substring(0,window.location.hash.indexOf('?')).inArray(noAuth) ?
0 :
$.ajax({
    url: config.server_host + '/api/userstate',
    type: 'get',
    success: function(data) {
        if (data.code != 200) {
            window.location.href = '#/login';
        }
    }
})
